package com.syc.activiti;

import org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl;
import org.activiti.engine.impl.interceptor.CommandContextInterceptor;
import org.activiti.engine.impl.interceptor.CommandInterceptor;
import org.springframework.context.annotation.Configuration;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * 自定义配置类
 */
@Configuration
public class TestConfiguration extends ProcessEngineConfigurationImpl {

    protected Collection<? extends CommandInterceptor> getDefaultCommandInterceptorsTxRequired() {
        // 创建一个拦截器集合
        List<CommandInterceptor> defaultCommandInterceptorsTxRequired = new ArrayList<CommandInterceptor>();
        // 添加自定义拦截器A
        defaultCommandInterceptorsTxRequired.add(new InterceptorA());
        // 添加系统的拦截器
        defaultCommandInterceptorsTxRequired.add(new CommandContextInterceptor(
                commandContextFactory, this));
        return defaultCommandInterceptorsTxRequired;
    }

    protected Collection<? extends CommandInterceptor> getDefaultCommandInterceptorsTxRequiresNew() {
        // 创建一个拦截器集合
        List<CommandInterceptor> defaultCommandInterceptorsTxRequired = new ArrayList<CommandInterceptor>();
        // 添加自定义拦截器
        defaultCommandInterceptorsTxRequired.add(new InterceptorB());
        return defaultCommandInterceptorsTxRequired;
    }

    @Override
    public CommandInterceptor createTransactionInterceptor() {
        return null;
    }

    public void initCommandInterceptors() {
        commandInterceptors = new ArrayList<CommandInterceptor>();
        commandInterceptors.add(new InterceptorA());
        commandInterceptors.add(new InterceptorB());
        super.initCommandInterceptors();
    }
}


